; Depots-con.LISP
; Icarus concepts, primitive skills, and goals for the Depots.

; Create a set of conceptual clauses for the Depots.
(create-concepts
 
 ((crate ?crate)
  :percepts ((crate ?crate)))

 ((pallet ?pallet)
  :percepts ((pallet ?pallet)))

 ((hoist ?hoist)
  :percepts ((hoist ?hoist)))

 ((truck ?truck)
  :percepts ((truck ?truck)))
 
 ((depot ?depot)
  :percepts ((depot ?depot)))

 ((truck-at ?truck ?depot)
  :percepts ((truck ?truck at ?depot)
	     (depot ?depot)))

 ((hoist-at ?hoist ?depot)
  :percepts ((hoist ?hoist at ?depot)
	     (depot ?depot)))

 ((pallet-at ?pallet ?depot)
  :percepts ((pallet ?pallet at ?depot)
	     (depot ?depot)))

 ((crate-at ?crate ?depot)
  :percepts ((crate ?crate at ?depot)
	     (depot ?depot)))
 
 ((on ?crate ?surface)
  :percepts ((crate ?crate xpos ?x1 ypos ?y1)
	     (pallet ?surface xpos ?x2 ypos ?y2 height ?h2)
	     (depot ?depot))
  :relations ((crate-at ?crate ?depot)
	      (pallet-at ?surface ?depot))
  :tests ((= ?x1 ?x2)
	  (= ?y1 (+ ?y2 ?h2))))

 ((on ?crate ?surface)
  :percepts ((crate ?crate xpos ?x1 ypos ?y1)
	     (crate ?surface xpos ?x2 ypos ?y2 height ?h2)
	     (depot ?depot))
  :relations ((crate-at ?crate ?depot)
	      (crate-at ?surface ?depot))
  :tests ((= ?x1 ?x2)
	  (= ?y1 (+ ?y2 ?h2))))

 ((in ?crate ?truck)
  :percepts ((crate ?crate inside ?truck)
	     (truck ?truck)))

 ((holding ?hoist ?crate)
  :percepts ((crate ?crate)
	     (hoist ?hoist status ?crate)))

 #|
 ((clear ?surface)
  :percepts ((crate ?surface))
  :relations ((not (on ?other-crate ?surface))
	      (not (in ?surface ?truck))
	      (not (holding ?hoist ?surface))))

 ((clear ?surface)
  :percepts ((pallet ?surface))
  :relations ((not (on ?any-crate ?surface))))
 |#
)

;Create a set of primitive skill clauses for the Depots.
(create-skills

 ((lift ?hoist ?crate ?from ?depot)
  :conditions ((hoist ?hoist)
	       (crate ?crate)
	       (crate ?from)
	       (depot ?depot)
	       (hoist-at ?hoist ?depot)
	       (crate-at ?crate ?depot)
	       (crate-at ?from ?depot)
	       (not (holding ?hoist ?any-crate))
	       (not (on ?any-crate ?crate))
	       (on ?crate ?from))
  :effects ((holding ?hoist ?crate)
	    ;(not (clear ?crate))
	    (not (on ?crate ?from)))
  :action (*grasp-and-lift ?hoist ?crate))

 ((lift ?hoist ?crate ?from ?depot)
  :conditions ((hoist ?hoist)
 	       (crate ?crate)
 	       (pallet ?from)
 	       (depot ?depot)
 	       (hoist-at ?hoist ?depot)
 	       (crate-at ?crate ?depot)
 	       (pallet-at ?from ?depot)
 	       (not (holding ?hoist ?any-crate))
 	       (not (on ?any-crate ?crate))
 	       (on ?crate ?from))
  :effects ((holding ?hoist ?crate)
 	    ;(not (clear ?crate))
 	    (not (on ?crate ?from)))
  :action (*grasp-and-lift ?hoist ?crate))
  
 ((drop ?hoist ?crate ?on-crate ?depot)
  :percepts ((crate ?on-crate xpos ?x ypos ?y height ?h))
  :conditions ((hoist ?hoist)
	       (crate ?crate)
	       (crate ?on-crate)
	       (depot ?depot)
	       (hoist-at ?hoist ?depot)
	       (crate-at ?on-crate ?depot)
	       (holding ?hoist ?crate)
	       (not (on ?any-crate ?on-crate)))
  :effects ((not (holding ?hoist ?crate))
	    ;(not (clear ?on-crate))
	    ;(clear ?crate)
	    (on ?crate ?on-crate))
  :action (*put-down-at-x-y ?hoist ?crate ?x (+ ?y ?h)))

 ((drop ?hoist ?crate ?on-pallet ?depot)
  :percepts ((pallet ?on-pallet xpos ?x ypos ?y height ?h))
  :conditions ((hoist ?hoist)
	       (crate ?crate)
	       (pallet ?on-pallet)
	       (depot ?depot)
	       (hoist-at ?hoist ?depot)
	       (pallet-at ?on-pallet ?depot)
	       (holding ?hoist ?crate)
	       (not (on ?any-crate ?on-pallet)))
  :effects ((not (holding ?hoist ?crate))
	    ;(not (clear ?on-pallet))
	    ;(clear ?crate)
	    (on ?crate ?on-pallet))
  :action (*put-down-at-x-y ?hoist ?crate ?x (+ ?y ?h)))

 ((load ?hoist ?crate ?truck ?depot)
  :conditions ((hoist ?hoist)
	       (crate ?crate)
	       (truck ?truck)
	       (depot ?depot)
	       (hoist-at ?hoist ?depot)
	       (crate-at ?crate ?depot)
	       (truck-at ?truck ?depot)
	       (holding ?hoist ?crate))
  :effects ((not (holding ?hoist ?crate))
	    (in ?crate ?truck))
  :action (*load-crate ?hoist ?crate ?truck))

 ((unload ?hoist ?crate ?truck ?depot)
  :conditions ((hoist ?hoist)
	       (crate ?crate)
	       (truck ?truck)
	       (depot ?depot)
	       (hoist-at ?hoist ?depot)
	       (truck-at ?truck ?depot)
	       (in ?crate ?truck)
	       (not (holding ?hoist ?any-crate)))
  :effects ((holding ?hoist ?crate)
	    (not (in ?crate ?truck)))
  :action (*unload-crate ?hoist ?crate))

 ((drive ?truck ?from ?to)
  :conditions ((truck ?truck)
	       (depot ?from)
	       (depot ?to)
	       (truck-at ?truck ?from))
  :effects ((truck-at ?truck ?to)
	    (not (truck-at ?truck ?from)))
  :action (*drive ?truck ?to))
)